package cn.hengzhu.main_manager.web.xcx;

import cn.hengzhu.main_manager.repository.dao.*;
import cn.hengzhu.main_manager.repository.domain.*;
import cn.hengzhu.main_manager.repository.vo.MapCoordinateVO;
import cn.hengzhu.main_manager.service.ManageCaseBoxService;
import cn.hengzhu.main_manager.utils.*;
import cn.hengzhu.main_manager.utils.config.AppConfig;
import cn.hengzhu.main_manager.utils.config.CaseUseTypeConst;
import cn.hengzhu.main_manager.utils.config.xcx.WxConfig;
import cn.hengzhu.main_manager.utils.httpssl.ClientCustomSSL;
import cn.hengzhu.main_manager.utils.xcx.AES256Utils;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.math.BigDecimal;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author 刘成
 * @since 2018年10月12日 微信小程序共享床
 */
@Controller
@RequestMapping("/xcx")
public class WXxcxController {
	private Logger log = Logger.getLogger(WXxcxController.class);
	@Autowired
	private ManageCaseMapper manageCaseMapper;
	@Autowired
	private CustomersAmountMapper customersAmountMapper;
	@Autowired
	private ManageCaseBoxMapper manageCaseBoxMapper;
	@Autowired
	private ManageCaseTypeMapper manageCaseTypeMapper;
	@Autowired
	private ManageCaseBoxService manageCaseBoxService;
	@Autowired
	private SysConstMapper sysConstMapper;
	@Autowired
	private PayOrderMapper payOrderMapper;
	@Autowired
	private ErrorLogRecordMapper errorLogRecordMapper;
	@Autowired
	private HelpCenterMapper helpCenterMapper;

	/**
	 * @author 刘成
	 * @since 2018年8月30日
	 * @param code
	 * @return 获取坐标
	 */
	@RequestMapping("/mapCoordinate")
	@ResponseBody
	public List<MapCoordinateVO> mapCoordinate(String code) {
		// 1.普通用途 2.医用床 3.快递 4.快餐 5.成人用品柜 6.智能医药柜
		List<ManageCase> allCase = manageCaseMapper.getAllCase();
		List<MapCoordinateVO> list = new ArrayList<>();
		if (!allCase.isEmpty()) {
			allCase.stream().forEach(a -> {
				MapCoordinateVO mapCoordinateVO = new MapCoordinateVO();
				mapCoordinateVO.setLatitude(a.getLatitude());
				mapCoordinateVO.setLongitude(a.getLongitude());
				Byte useType = a.getUseType();
				if (Byte.valueOf("1").equals(useType)) {
					mapCoordinateVO.setIconPath(AppConfig.BOX);
				} else if (Byte.valueOf("2").equals(useType)) {
					mapCoordinateVO.setIconPath(AppConfig.BED);
				} else if (Byte.valueOf("3").equals(useType)) {
					mapCoordinateVO.setIconPath(AppConfig.FAST);
				} else if (Byte.valueOf("4").equals(useType)) {
					mapCoordinateVO.setIconPath(AppConfig.FOOD);
				}
				list.add(mapCoordinateVO);
			});
		}
		return list;
	}

	/**
	 * @author 刘成
	 * @since 2018年8月28日
	 * @param code
	 * @return 获取用户的Id
	 */
	@RequestMapping("/getOpenId")
	@ResponseBody
	public Map<String, String> getOpenId(String code) {
		Map<String, String> map = new HashMap<>();
		// 获取openID
		String appid = WxConfig.APPID;
		String secret = WxConfig.SECRET;
		String url = WxConfig.GET_OPENID.replace("APPID", appid).replace("SECRET", secret).replace("JSCODE", code);
		String httpGet = HttpClientUtil.httpGet(url);
		JSONObject parseObject = JSONObject.parseObject(httpGet);
		String openId = (String) parseObject.get("openid");
		map.put("openId", openId);
		// 查询是否有账号，，，没有就新建，，，有就不管
		CustomersAmountExample example = new CustomersAmountExample();
		example.createCriteria().andOpenIdEqualTo(openId).andSourceEqualTo(Byte.valueOf("2"));
		List<CustomersAmount> selectByExample = customersAmountMapper.selectByExample(example);
		if (selectByExample.isEmpty()) {
			CustomersAmount customersAmount = new CustomersAmount();
			customersAmount.setCreateTime(new Date());
			customersAmount.setOpenId(openId);
			customersAmount.setSource((byte) 2);
			customersAmountMapper.insertSelective(customersAmount);
		}

		return map;
	}

	/**
	 * @author 刘成
	 * @since 2018年8月13日
	 * @param caseNo
	 * @return 用户基本信息、
	 *
	 */
	@RequestMapping("/userInfo")
	@ResponseBody
	public Map<String, Object> userInfo(String openId) {
		// 查询所需缴纳的押金数额
		// SysConstExample payexample = new SysConstExample();
		// payexample.createCriteria().andNameEqualTo(AppConfig.ASSURE_AMOUNT);
		// List<SysConst> selectByExample2 = sysConstMapper.selectByExample(payexample);
		// 需缴纳的押金数
		// String payNum = selectByExample2.get(0).getValue();
		// Double valueOf = Double.valueOf(payNum);
		// Double ass = valueOf / 100;

		Map<String, Object> map = new HashMap<>();
		BigDecimal assureAmount = BigDecimal.ZERO;
		String totalAmount = "0.0";
		Byte isPay = 0;
		Integer integral = 0;
		String useTime = "00:00:00";
		// 根据openID查询用户的账户信息并返回查询结果
		CustomersAmountExample example = new CustomersAmountExample();
		example.createCriteria().andOpenIdEqualTo(openId).andSourceEqualTo(Byte.valueOf("2"));
		List<CustomersAmount> selectByExample = customersAmountMapper.selectByExample(example);
		if (!selectByExample.isEmpty()) {// 有
			CustomersAmount customersAmount = selectByExample.get(0);
			// 是否缴纳押金
			isPay = customersAmount.getIsPay();
			// 所交押金数额
			// payNum = customersAmount.getAssureAmount().toString();
			// 账户积分
			integral = customersAmount.getIntegral();
			// 账户余额
			BigDecimal total = customersAmount.getTotalAmount();
			totalAmount = total.toString();
			if (Byte.valueOf("1").equals(isPay)) {// 缴纳
				assureAmount = customersAmount.getAssureAmount();
			}
			// 查询使用情况

			ManageCaseBoxExample caseBoxExample = new ManageCaseBoxExample();
			caseBoxExample.createCriteria().andUserIdEqualTo(openId).andUseStatusEqualTo((byte) 1)
					.andIsDelEqualTo((byte) 0);
			List<ManageCaseBox> list = manageCaseBoxMapper.selectByExample(caseBoxExample);
			Map<String, ManageCaseBox> collect = list.stream()
					.collect(Collectors.toMap(ManageCaseBox::getCaseNo, a -> a));
			List<String> caseNoList = list.stream()
					.collect(Collectors.mapping(ManageCaseBox::getCaseNo, Collectors.toList()));
			if (caseNoList != null && !caseNoList.isEmpty()) {

				ManageCaseExample caseExample = new ManageCaseExample();
				caseExample.createCriteria().andUseTypeEqualTo((byte) 2).andCaseNoIn(caseNoList);
				List<ManageCase> selectByExample3 = manageCaseMapper.selectByExample(caseExample);

				if (!selectByExample3.isEmpty()) {
					ManageCase manageCase = selectByExample3.get(0);

					String caseNo = manageCase.getCaseNo();
					ManageCaseBox manageCaseBox = collect.get(caseNo);
					Date saveTime = manageCaseBox.getSaveTime();
					Date date = new Date();
					long time = date.getTime() - saveTime.getTime();
					useTime = TimeFormatUtil.getMinutesTime(time);
				}
			}
		} else {// 没有
				// 第一次使用，，，插入数据
			CustomersAmount customersAmount = new CustomersAmount();
			customersAmount.setCreateTime(new Date());
			customersAmount.setOpenId(openId);
			customersAmount.setSource((byte) 2);
			customersAmountMapper.insertSelective(customersAmount);
		}
		map.put("assureAmount", assureAmount);
		map.put("totalAmount", totalAmount);
		map.put("isPay", isPay);
		map.put("useTime", useTime);
		map.put("openId", openId);
		// map.put("payNum", payNum);
		map.put("integral", integral);
		return map;
	}

	/**
	 * @author 刘成
	 * @since 2018年8月23日
	 * @param openId
	 * @return 使用时间
	 */
	@RequestMapping("/useTime")
	@ResponseBody
	public Map<String, String> useTime(String openId) {
		Map<String, String> map = new HashMap<>();
		String minutesTime = "00:00:00";

		// SELECT
		// <include refid="Base_Column_List" />
		// from
		// manage_case_box
		// where
		// USER_ID=#{openId}
		// AND USE_STATUS=1
		// and IS_DEL=0

		ManageCaseBoxExample example = new ManageCaseBoxExample();
		example.createCriteria().andUserIdEqualTo(openId).andUseStatusEqualTo((byte) 1).andIsDelEqualTo((byte) 0);
		List<ManageCaseBox> list = manageCaseBoxMapper.selectByExample(example);

		Map<String, ManageCaseBox> collect = list.stream().collect(Collectors.toMap(ManageCaseBox::getCaseNo, a -> a));
		List<String> caseNoList = list.stream()
				.collect(Collectors.mapping(ManageCaseBox::getCaseNo, Collectors.toList()));
		if (caseNoList != null && !caseNoList.isEmpty()) {

			ManageCaseExample caseExample = new ManageCaseExample();
			caseExample.createCriteria().andUseTypeEqualTo((byte) 2).andCaseNoIn(caseNoList);
			List<ManageCase> selectByExample = manageCaseMapper.selectByExample(caseExample);
			if (!selectByExample.isEmpty()) {
				ManageCase manageCase = selectByExample.get(0);
				String caseNo = manageCase.getCaseNo();
				ManageCaseBox manageCaseBox = collect.get(caseNo);
				Date saveTime = manageCaseBox.getSaveTime();
				Date date = new Date();
				long time = date.getTime() - saveTime.getTime();
				minutesTime = TimeFormatUtil.getMinutesTime(time);
			}
		}
		map.put("minutesTime", minutesTime);
		return map;
	}

	/**
	 * @author 刘成
	 * @since 2018年8月23日
	 * @param caseNo
	 * @return 箱子的收费等信息
	 */
	@RequestMapping("/boxInfo")
	@ResponseBody
	public Map<String, String> boxInfo(String caseNo) {
		caseNo = caseNo.substring(3);
		Map<String, String> map = new HashMap<>();
		//
		ManageCaseExample example = new ManageCaseExample();
		example.createCriteria().andCaseNoEqualTo(caseNo);
		List<ManageCase> selectByExample = manageCaseMapper.selectByExample(example);

		if (!selectByExample.isEmpty()) {

			ManageCase caseByCaseNo = selectByExample.get(0);

			Integer typeId = caseByCaseNo.getTypeId();
			// 查询type的类型
			ManageCaseType selectByPrimaryKey = manageCaseTypeMapper.selectByPrimaryKey(typeId);
			Byte payType = selectByPrimaryKey.getPayType();
			// 收费类型（0，免费 1.计时 2.记次）'
			if (Byte.valueOf("0").equals(payType)) {
				map.put("jump", "8");
				map.put("hzmessageyy", "您好，此柜为免费柜，但需要缴纳押金，请放心你使用");
			} else if (Byte.valueOf("1").equals(payType)) {
				String price = selectByPrimaryKey.getPrice();
				String userTime = selectByPrimaryKey.getUserTime();
				Integer sss = Integer.valueOf(userTime) * 2;
				String string = sss.toString();
				map.put("jump", "8");
				map.put("hzmessageyy", "您好，此柜需要缴纳押金,此柜的收费标准为:" + userTime + "小时" + price + "元，不足" + userTime + "小时按"
						+ userTime + "小时计费，超过" + userTime + "小时不足" + string + "小时按" + string + "小时计费，以此类推");
			} else if (Byte.valueOf("2").equals(payType)) {
				String price = selectByPrimaryKey.getPrice();
				map.put("jump", "8");
				map.put("hzmessageyy", "您好，此柜需要缴纳押金,此柜收费标准为:，每次" + price + "元");
			}
		} else {
			map.put("jump", "0");
			map.put("hzmessageyy", "你扫描的二维码有误，请重试");
		}

		return map;
	}

	/**
	 * @author 刘成
	 * @since 2018年8月21日
	 * @param caseNo
	 * @return
	 * @throws Exception
	 *             开柜
	 */
	@RequestMapping("/openbox")
	@ResponseBody
	public Map<String, String> openbox(String caseNo, String openId) throws Exception {
		Byte useType = CaseUseTypeConst.HOSPITAL_BED_CASE;// 用途为医用床
		Map<String, String> map = new HashMap<>();
		// 开柜前
		// 1.查询是否缴纳押金
		CustomersAmountExample amountExample = new CustomersAmountExample();
		amountExample.createCriteria().andOpenIdEqualTo(openId).andSourceEqualTo((byte) 2);
		List<CustomersAmount> selectByExample = customersAmountMapper.selectByExample(amountExample);
		if (!selectByExample.isEmpty()) {// 先判断有无账户
			CustomersAmount customersAmount = selectByExample.get(0);
			Byte isPay = customersAmount.getIsPay();
			BigDecimal totalAmount = customersAmount.getTotalAmount();
			double doubleValue = totalAmount.doubleValue();
			if (Byte.valueOf("0").equals(isPay)) {// 未缴纳押金
				map.put("jumpPage", "1");
				map.put("openboxMessage", "请先缴纳押金再使用此柜，点击确定进行押金缴纳");
				return map;
			} else if (Byte.valueOf("2").equals(isPay)) {
				map.put("jumpPage", "0");
				map.put("openboxMessage", "您已申请退回押金，暂时不能使用此类储物柜");
				return map;
			} else {// 剩下的为已缴纳押金或者押金退回失败的
					// 2.查询是否欠费
				if (doubleValue >= 0) {// 正常开启
					///////////////////////////////////////////////////////////////////
					Date date = new Date();
					// 查询是否已经在使用中
					int count = manageCaseBoxMapper.selectByOpenIdAndUseType(openId, useType);
					if (count > 0) {
						map.put("jumpPage", "0");
						map.put("openboxMessage", "您已经使用了此类储物柜，不能再开启此类储物柜");
						return map;
					} else {

						ManageCaseBoxExample example = new ManageCaseBoxExample();
						example.createCriteria().andIsDelEqualTo((byte) 0).andUseStatusEqualTo((byte) 0)
								.andSwitchStatusEqualTo((byte) 1).andCaseNoEqualTo(caseNo);
						List<ManageCaseBox> list = manageCaseBoxMapper.selectByExample(example);

						if (!list.isEmpty()) {
							ManageCaseBox manageCaseBox = list.get(0);
							Integer doorNum = manageCaseBox.getDoorNum();
							Connection connection = ConnectionUtils.getConnection();
							Channel channel = connection.createChannel();
							Map<String, Object> sendMap = new HashMap<>();
							sendMap.put("door", doorNum);
							sendMap.put("timestamp", date.getTime());
							ObjectMapper mapper = new ObjectMapper();
							Map<String, Object> args = new HashMap<String, Object>();
							args.put("x-message-ttl", 40000);
							channel.queueDeclare(caseNo, true, false, false, args);
							String writeValueAsString = mapper.writeValueAsString(sendMap);
							try {
								// 3.缴纳了押金又没有欠费，执行开柜操作
								manageCaseBoxService.openBoxByXcx(manageCaseBox, openId);
								channel.basicPublish("", caseNo, null, writeValueAsString.getBytes());
								channel.close();
								connection.close();
								map.put("jumpPage", "200");
								map.put("openboxMessage", "开启成功，请放心使用");
								return map;

							} catch (Exception e) {
								map.put("jumpPage", "0");
								map.put("openboxMessage", "开启失败，请重新");
								return map;
							}
						} else {
							map.put("jumpPage", "0");
							map.put("openboxMessage", "没有空余的箱子了");
							return map;
						}
					}
				} else {
					map.put("jumpPage", "2");
					map.put("openboxMessage", "您已欠费，请充值后再使用，点击确定进行充值");
					return map;
				}
			}
		} else {
			CustomersAmount customersAmount = new CustomersAmount();
			customersAmount.setCreateTime(new Date());
			customersAmount.setOpenId(openId);
			customersAmount.setSource((byte) 2);
			customersAmountMapper.insertSelective(customersAmount);
			map.put("openboxMessage", "请先缴纳押金再使用此柜，点击确定进行押金缴纳");
			return map;

		}
	}


	/**
	 * @author 刘成
	 * @since 2018年8月9日
	 * @param openId
	 * @param totalFee 充值金额 分为单位
	 * @return
	 * @throws Exception
	 *             充值
	 */
	@RequestMapping("/recharge")
	@ResponseBody
	public Map<String, String> recharge(String openId, String totalFee) throws Exception {
		totalFee = String.valueOf(Math.abs(Integer.parseInt(totalFee)));

		Map<String, String> map = new HashMap<>();
		String notify_url = WxConfig.DOMAIN_URL + "/xcx/payCallback"; //通知地址 回调服务器 支付结果
		String MCHID = WxConfig.MCH_ID; // 商务号
		String KEY = WxConfig.KEY;	// 商务秘钥
		String appid = WxConfig.APPID; // 小程序appID
		Date date = new Date();
		// 产生随机数
		String body = "账户充值";
		String nonce_str = DictionaryUtils.getRandomStr(); //生产随机字符串
		String out_trade_no = "cz" + date.getTime() + nonce_str.substring(0, 2);

		map.put("appid", appid);
		map.put("mch_id", MCHID);
		map.put("nonce_str", nonce_str);
		map.put("body", body);
		map.put("out_trade_no", out_trade_no);
		map.put("total_fee", totalFee);
		map.put("spbill_create_ip", "127.0.0.1");
		map.put("notify_url", notify_url); //回掉地址
		map.put("trade_type", "JSAPI");
		map.put("openid", openId);
		String stringA = DictionaryUtils.formatUrlMap(map, false, false); // 转换成url
		String stringSignTemp = stringA + "&key=" + KEY;
		String sign = Md5Util.wxXcxHash(stringSignTemp).toUpperCase();  // 加密并变为大写

		// 将参数 编写XML格式
		StringBuffer paramBuffer = new StringBuffer();
		paramBuffer.append("<xml>");
		paramBuffer.append("<appid>" + appid + "</appid>");
		paramBuffer.append("<mch_id>" + MCHID + "</mch_id>");
		paramBuffer.append("<nonce_str>" + nonce_str + "</nonce_str>");
		paramBuffer.append("<sign>" + sign + "</sign>");
		paramBuffer.append("<body>" + body + "</body>");
		paramBuffer.append("<out_trade_no>" + out_trade_no + "</out_trade_no>");
		paramBuffer.append("<total_fee>" + totalFee + "</total_fee>");
		paramBuffer.append("<spbill_create_ip>" + map.get("spbill_create_ip") + "</spbill_create_ip>");
		paramBuffer.append("<notify_url>" + map.get("notify_url") + "</notify_url>");
		paramBuffer.append("<trade_type>" + map.get("trade_type") + "</trade_type>");
		paramBuffer.append("<openid>" + openId + "</openid>");
		paramBuffer.append("</xml>");

		// WxConfig.URL 统一下单接口 ， 这里就已经发送请求了
		String remotePortData = getRemotePortData(WxConfig.URL,
				new String(paramBuffer.toString().getBytes("UTF-8"), "ISO8859-1"));

		InputStream is = new ByteArrayInputStream(remotePortData.getBytes()); // 输入流
		InputStreamReader isReader = new InputStreamReader(is, "utf-8");
		Map<String, String> map1 = XmlPullUtil.parse(isReader); // 解析消息

		// 拿到接口返回值，插入记录
		String prepay_id = map1.get("prepay_id");
		// 请求订单号成功
		if (StringUtils.isNotBlank(prepay_id)) {

			PayOrder record = new PayOrder();
			record.setCreartTime(date);
			record.setOpenId(openId); // 微信用户唯一标识
			record.setOutTradeNo(out_trade_no); // 交易编号
			record.setTotalFee(Integer.valueOf(totalFee)); // 金额
			// 在数据库中插入订单记录 pay_order
			payOrderMapper.insertSelective(record); // date 用户唯一标识  交易编号 交易金额

			long seconds = new Date().getTime();
			Map<String, String> paySignMap = new HashMap<>();
			paySignMap.put("appId", appid);
			paySignMap.put("timeStamp", String.valueOf(seconds));
			paySignMap.put("nonceStr", nonce_str);
			paySignMap.put("package", "prepay_id=" + prepay_id); // 订单号
			paySignMap.put("signType", "MD5");
			String stringPay = DictionaryUtils.formatUrlMap(paySignMap, false, false); // 转化成url
			String paySign = WXMD5Util.MD5Encode(stringPay + "&key=" + KEY).toUpperCase(); // 加密
			map1.put("timeStamp", String.valueOf(seconds));
			map1.put("nonceStr", nonce_str);
			map1.put("package", "prepay_id=" + prepay_id);
			map1.put("signType", "MD5");
			map1.put("paySign", paySign);
		}
		return map1;
	}

	/**
	 * @author 刘成
	 * @since 2018年8月23日
	 * @param openId
	 * @param
	 * @return
	 * @throws Exception
	 *             缴纳押金
	 */
	@RequestMapping("/payCase")
	@ResponseBody
	public Map<String, String> payCase(String openId) throws Exception {
		Map<String, String> map = new HashMap<>();

		SysConstExample payexample = new SysConstExample();
		payexample.createCriteria().andNameEqualTo(AppConfig.ASSURE_AMOUNT);
		List<SysConst> selectByExample2 = sysConstMapper.selectByExample(payexample);
		// 需缴纳的押金数
		String totalFee = selectByExample2.get(0).getValue();

		String notify_url = WxConfig.DOMAIN_URL + "/xcx/payCallback";
		String MCHID = WxConfig.MCH_ID;
		String KEY = WxConfig.KEY;
		String appid = WxConfig.APPID;
		Date date = new Date();
		// 产生随机数
		String body = "押金支付";
		String nonce_str = DictionaryUtils.getRandomStr();
		String out_trade_no = "yj" + date.getTime() + nonce_str.substring(0, 2);
		map.put("appid", appid);
		map.put("mch_id", MCHID);
		map.put("nonce_str", nonce_str);
		map.put("body", body);
		map.put("out_trade_no", out_trade_no);
		map.put("total_fee", totalFee);
		map.put("spbill_create_ip", "127.0.0.1");
		map.put("notify_url", notify_url);
		map.put("trade_type", "JSAPI");
		map.put("openid", openId);
		String stringA = DictionaryUtils.formatUrlMap(map, false, false);
		String stringSignTemp = stringA + "&key=" + KEY;
		String sign = Md5Util.wxXcxHash(stringSignTemp).toUpperCase();

		// 将参数 编写XML格式
		StringBuffer paramBuffer = new StringBuffer();
		paramBuffer.append("<xml>");
		paramBuffer.append("<appid>" + appid + "</appid>");
		paramBuffer.append("<mch_id>" + MCHID + "</mch_id>");
		paramBuffer.append("<nonce_str>" + nonce_str + "</nonce_str>");
		paramBuffer.append("<sign>" + sign + "</sign>");
		paramBuffer.append("<body>" + body + "</body>");
		paramBuffer.append("<out_trade_no>" + out_trade_no + "</out_trade_no>");
		paramBuffer.append("<total_fee>" + totalFee + "</total_fee>");
		paramBuffer.append("<spbill_create_ip>" + map.get("spbill_create_ip") + "</spbill_create_ip>");
		paramBuffer.append("<notify_url>" + map.get("notify_url") + "</notify_url>");
		paramBuffer.append("<trade_type>" + map.get("trade_type") + "</trade_type>");
		paramBuffer.append("<openid>" + openId + "</openid>");
		paramBuffer.append("</xml>");

		String remotePortData = getRemotePortData(WxConfig.URL,
				new String(paramBuffer.toString().getBytes(), "ISO8859-1"));

		InputStream is = new ByteArrayInputStream(remotePortData.getBytes());
		InputStreamReader isReader = new InputStreamReader(is, "utf-8");
		Map<String, String> map1 = XmlPullUtil.parse(isReader);

		// 拿到接口返回值，插入记录
		String prepay_id = map1.get("prepay_id");
		// 请求订单号成功
		if (StringUtils.isNotBlank(prepay_id)) {
			PayOrder record = new PayOrder();
			record.setCreartTime(date);
			record.setOpenId(openId);
			record.setOutTradeNo(out_trade_no);
			record.setTotalFee(Integer.valueOf(totalFee));
			// 在数据库中插入订单记录
			payOrderMapper.insertSelective(record);

			long seconds = new Date().getTime();
			Map<String, String> paySignMap = new HashMap<>();
			paySignMap.put("appId", appid);
			paySignMap.put("timeStamp", String.valueOf(seconds));
			paySignMap.put("nonceStr", nonce_str);
			paySignMap.put("package", "prepay_id=" + prepay_id);
			paySignMap.put("signType", "MD5");
			String stringPay = DictionaryUtils.formatUrlMap(paySignMap, false, false);
			String paySign = WXMD5Util.MD5Encode(stringPay + "&key=" + KEY).toUpperCase();
			map1.put("timeStamp", String.valueOf(seconds));
			map1.put("nonceStr", nonce_str);
			map1.put("package", "prepay_id=" + prepay_id);
			map1.put("signType", "MD5");
			map1.put("paySign", paySign);
		}
		return map1;

	}

	/**
	 * @author 刘成
	 * @since 2018年8月24日
	 * @param openId
	 * @param
	 * @return
	 * @throws Exception
	 *             退还押金
	 */
	@RequestMapping("/backPay")
	@ResponseBody
	public Map<String, String> backPay(String openId) throws Exception {
		// ManageCase manageCase = null;
		Map<String, String> restultMap = new HashMap<>();
		log.info("微信退款申请。。。。");
		// 首先查询是否在使用中
		ManageCaseBoxExample caseBoxExample = new ManageCaseBoxExample();
		caseBoxExample.createCriteria().andUserIdEqualTo(openId).andUseStatusEqualTo((byte) 1)
				.andIsDelEqualTo((byte) 0);
		List<ManageCaseBox> list = manageCaseBoxMapper.selectByExample(caseBoxExample);
		// log.info("listSize:" + list.size());
		// List<String> caseNoList = list.stream()
		// .collect(Collectors.mapping(ManageCaseBox::getCaseNo, Collectors.toList()));
		// if (caseNoList != null && !caseNoList.isEmpty()) {
		// log.info("caseNoList不为空");
		// ManageCaseExample caseExample = new ManageCaseExample();
		// caseExample.createCriteria().andUseTypeEqualTo((byte)
		// 2).andCaseNoIn(caseNoList);
		// List<ManageCase> selectByExample =
		// manageCaseMapper.selectByExample(caseExample);
		// if (!selectByExample.isEmpty()) {
		// log.info("manageCasse:获取值");
		// manageCase = selectByExample.get(0);
		// }
		// }
		if (!list.isEmpty()) {
			log.info("使用中，不能进行此操作");
			restultMap.put("jumpPage", "0");
			restultMap.put("message", "使用中，不能进行此操作");
		} else {
			log.info("未使用。");
			Map<String, String> map = new HashMap<>();
			String MCHID = WxConfig.MCH_ID;
			String KEY = WxConfig.KEY;
			String appid = WxConfig.APPID;
			// 查询用户账户信息（1.是否有欠款 2.是否交了押金）
			CustomersAmountExample example = new CustomersAmountExample();
			example.createCriteria().andOpenIdEqualTo(openId).andSourceEqualTo((byte) 2);
			List<CustomersAmount> customersAmountList = customersAmountMapper.selectByExample(example);
			if (!customersAmountList.isEmpty()) {
				CustomersAmount customersAmount = customersAmountList.get(0);
				BigDecimal totalAmount = customersAmount.getTotalAmount();
				double total = totalAmount.doubleValue();
				if (total >= 0) {
					Byte isPay = customersAmount.getIsPay();
					if (Byte.valueOf("0").equals(isPay)) {// 没有缴纳押金
						restultMap.put("jumpPage", "2");
						restultMap.put("message", "您没有押金需要退还");
					} else if (Byte.valueOf("2").equals(isPay)) {// 押金退还中
						restultMap.put("jumpPage", "0");
						restultMap.put("message", "退还押金中......请耐心等待.....");
					} else if (Byte.valueOf("3").equals(isPay)) {// 押金退还失败
						restultMap.put("jumpPage", "0");
						restultMap.put("message", "因未知原因退还失败，我们会尽快处理，感谢你的使用和支持");
						return restultMap;
					} else if (Byte.valueOf("1").equals(isPay)) {// 正常状态，可以退还押金
						String assureTransactionId = customersAmount.getAssureTransactionId();

						BigDecimal totalPledge = customersAmount.getTotalPledge();// 总金额 单位为分
						// Double pledgeVlaue = totalPledge.doubleValue() * 100;//转为分
						int totalFee = totalPledge.intValue();
						BigDecimal assureAmount = customersAmount.getAssureAmount();// 押金 单位为元
						Double doubleValue = assureAmount.doubleValue() * 100;// 转为分
						int intValue = doubleValue.intValue();
						if (intValue <= 0) {
							restultMap.put("jumpPage", "2");
							restultMap.put("message", "没有可退押金");
							return restultMap;
						}

						Date date = new Date();
						String nonce_str = DictionaryUtils.getRandomStr();
						String out_refund_no = "tk" + date.getTime() + nonce_str.substring(0, 2);
						log.info("退款信息为：transaction_id:" + assureTransactionId + " totalFee:" + totalFee + " refundFee:"
								+ intValue);
						map.put("appid", appid);
						map.put("mch_id", MCHID);
						map.put("nonce_str", nonce_str);
						map.put("transaction_id", assureTransactionId);
						map.put("out_refund_no", out_refund_no);
						map.put("total_fee", String.valueOf(totalFee));
						map.put("refund_fee", String.valueOf(intValue));
						map.put("refund_account", "REFUND_SOURCE_RECHARGE_FUNDS");
						map.put("notify_url", WxConfig.DOMAIN_URL + "/xcx/backPayNotify");
						String stringA = DictionaryUtils.formatUrlMap(map, false, false);
						String stringSignTemp = stringA + "&key=" + KEY;
						String sign = Md5Util.wxXcxHash(stringSignTemp).toUpperCase();

						StringBuffer paramBuffer = new StringBuffer();
						paramBuffer.append("<xml>");
						paramBuffer.append("<appid>" + appid + "</appid>");
						paramBuffer.append("<mch_id>" + MCHID + "</mch_id>");
						paramBuffer.append("<nonce_str>" + nonce_str + "</nonce_str>");
						paramBuffer.append("<sign>" + sign + "</sign>");
						paramBuffer.append("<transaction_id>" + assureTransactionId + "</transaction_id>");
						paramBuffer.append("<out_refund_no>" + out_refund_no + "</out_refund_no>");
						paramBuffer.append("<total_fee>" + String.valueOf(totalFee) + "</total_fee>");
						paramBuffer.append("<refund_fee>" + String.valueOf(intValue) + "</refund_fee>");
						paramBuffer.append("<refund_account>" + "REFUND_SOURCE_RECHARGE_FUNDS" + "</refund_account>");
						paramBuffer
								.append("<notify_url>" + WxConfig.DOMAIN_URL + "/xcx/backPayNotify" + "</notify_url>");
						paramBuffer.append("</xml>");
						String postData = ClientCustomSSL.postData(WxConfig.BACKPAY_URL,
								new String(paramBuffer.toString().getBytes(), "ISO8859-1"));

						InputStream is = new ByteArrayInputStream(postData.getBytes());
						InputStreamReader isReader = new InputStreamReader(is, "utf-8");
						Map<String, String> map1 = XmlPullUtil.parse(isReader);

						map1.put("amountId", customersAmount.getAmountId().toString());
						String result_code = map1.get("result_code");
                        log.info("退款状态为：result_code:" + result_code + " map1:" + map1.toString());
						if (StringUtils.isNotBlank(result_code) && result_code.equals("SUCCESS")) {// 退款申请成功
							// 1.申请提交成功后，先改变押金状态为退款中
							// 2.在退款的表中插入一条数据
							try {
								manageCaseBoxService.backPayApply(map1);
								restultMap.put("jumpPage", "0");
								restultMap.put("message", "退款申请已发送成功");
							} catch (Exception e) {
								restultMap.put("jumpPage", "0");
								restultMap.put("message", "退款申请已发送成功");
								ErrorLogRecord record = new ErrorLogRecord();
								record.setErrorType("退款消息插入失败，资金账户ID：" + customersAmount.getAmountId());
								errorLogRecordMapper.insertSelective(record);
							}
						} else {
							restultMap.put("jumpPage", "0");
							restultMap.put("message", "未知错误，请稍后重试");
						}
					} else {
						restultMap.put("jumpPage", "0");
						restultMap.put("message", "退款失败");
					}
				} else {
					restultMap.put("jumpPage", "1");
					restultMap.put("message", "您已欠费，请充值后再进行提现操作");
				}

			} else {
				restultMap.put("jumpPage", "0");
				restultMap.put("message", "系统错误");
			}

		}
		return restultMap;
	}

	/**
	 * @author 刘成
	 * @since 2018年9月5日
	 * @return 提现
	 * @throws Exception
	 * @throws UnsupportedEncodingException
	 */
	@RequestMapping("/withdrawDeposit")
	@ResponseBody
	// TODO 账户问题，暂时不同此接口
	public Map<String, String> withdrawDeposit(String openId, Integer amount) throws Exception {
		Map<String, String> map = new HashMap<>();
		Date date = new Date();
		String KEY = WxConfig.KEY;
		String mch_appid = WxConfig.APPID;
		String mchid = WxConfig.MCH_ID;
		String nonce_str = DictionaryUtils.getRandomStr();
		String partner_trade_no = "tx" + date.getTime() + nonce_str.substring(1, 3);
		String check_name = "NO_CHECK";
		amount = amount * 100;
		String desc = "余额提现";
		String spbill_create_ip = "127.0.0.1";

		map.put("mch_appid", mch_appid);
		map.put("mchid", mchid);
		map.put("nonce_str", nonce_str);
		map.put("partner_trade_no", partner_trade_no);
		map.put("check_name", check_name);
		map.put("amount", amount.toString());
		map.put("desc", desc);
		map.put("spbill_create_ip", spbill_create_ip);
		map.put("openid", openId);
		String stringA = DictionaryUtils.formatUrlMap(map, false, false);
		String stringSignTemp = stringA + "&key=" + KEY;
		String sign = Md5Util.wxXcxHash(stringSignTemp).toUpperCase();

		StringBuffer paramBuffer = new StringBuffer();
		paramBuffer.append("<xml>");
		paramBuffer.append("<mch_appid>" + mch_appid + "</mch_appid>");
		paramBuffer.append("<mchid>" + mchid + "</mchid>");
		paramBuffer.append("<nonce_str>" + nonce_str + "</nonce_str>");
		paramBuffer.append("<sign>" + sign + "</sign>");
		paramBuffer.append("<partner_trade_no>" + partner_trade_no + "</partner_trade_no>");
		paramBuffer.append("<openid>" + openId + "</openid>");
		paramBuffer.append("<check_name>" + check_name + "</check_name>");
		paramBuffer.append("<amount>" + amount + "</amount>");
		paramBuffer.append("<desc>" + desc + "</desc>");
		paramBuffer.append("<spbill_create_ip>" + spbill_create_ip + "</spbill_create_ip>");
		paramBuffer.append("</xml>");

		String postData = ClientCustomSSL.postData(WxConfig.BACKPAY_URL,
				new String(paramBuffer.toString().getBytes(), "ISO8859-1"));
		InputStream is = new ByteArrayInputStream(postData.getBytes());
		InputStreamReader isReader = new InputStreamReader(is, "utf-8");
		Map<String, String> map1 = XmlPullUtil.parse(isReader);

		return map1;
	}

	/**
	 * @author 刘成
	 * @throws IOException
	 * @since 2018年9月25日 获取微信小程序二维码
	 */
	@RequestMapping("/getWXxcxCode")
	@ResponseBody
	public ResponseEntity<byte[]> getWXxcxCode(HttpServletResponse response) throws IOException {
		// BASE64Decoder decoder = new BASE64Decoder();
		// Decoder decoder=new Decoder();
		Map<String, Object> map = new HashMap<>();
		String url = WxConfig.GET_TOKEN.replace("APPID", WxConfig.APPID).replace("APPSECRET", WxConfig.SECRET);
		String httpGet = HttpClientUtil.httpGet(url);
		JSONObject parseObject = JSONObject.parseObject(httpGet);
		String access_token = (String) parseObject.get("access_token");
		String replace = WxConfig.WXA_CODE.replace("ACCESS_TOKEN", access_token);
		map.put("scene", "10:d0:7a:22:70:7e");
		map.put("page", "pages/map/map");
		map.put("is_hyaline", true);
		String jsonString = JSONObject.toJSONString(map);
		byte[] httpPostImage = HttpClientUtil.httpPostImage(replace, jsonString);

		HttpHeaders responseHeaders = new HttpHeaders();
		responseHeaders.set("Content-Type", "image/jpg");
		return new ResponseEntity<byte[]>(httpPostImage, responseHeaders, HttpStatus.CREATED);
	}

	/**
	 * @author 刘成
	 * @since 2018年8月27日
	 * @param request
	 * @param response
	 *            退款结果通知接口
	 * @throws Exception
	 */
	@RequestMapping("/backPayNotify")
	@ResponseBody
	public String backPayNotify(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String inputLine = "";
		String notityXml = "";
		while ((inputLine = request.getReader().readLine()) != null) {
			notityXml += inputLine;
		}
		// 关闭流
		request.getReader().close();

		// 解析成Map

		InputStream is = new ByteArrayInputStream(notityXml.getBytes());
		InputStreamReader isReader = new InputStreamReader(is, "utf-8");
		Map<String, String> map = XmlPullUtil.parse(isReader);
		// {nonce_str=d188233a9bb24aee9a85a678b83cf7c4,
		// req_info=5zudS2mXaOXZ/fZHVtyHiqE1bX7uYAYLEVkuXVeK9TNgg4pnuqX82p5XTdeWni8axz3hf0AlPAAN1VJhujHJgDVX9cuGNvq9VE8SiTp6yqpbOsGMo6hDcC5ZqwGDfWbFabX10UfmEpo7glxsBqNg3keGYTBKcnIlGWqSoK/w0AzWENzKLqM5Q/GhJE0HUiSOL/I42i47n855kyHm7ZH9PK676tdm6D8CJ0JUq9nfnrb2TBy116coNNsQJ7n7UQikfPLb/ZKGQmpAhRkKkamyvcYDey7rzhTbE9BUQhOFD9P93FAsnHk3VdXR+6pJFCSHkkN5dkX3UbV4OCVDHDP/cctdyRVyAhgrSGN1UE8vNSCOIRUsFH8JVgN6gSxag7+heO4Q9nJl72kCMR99+fo2VbteqdMXI39vsRQXGx0+6qa51cRktCjD4UzQrC5DPRKdMEhw8Scs0qYd7aK5xwstBx1rJNKSRGkXyV0FRbkRY3aFC4hZ+DtA2WtnFTJpKr/uQGoI8gXrlDoJBafLAexuHWTOEqfay8SZoo4KWNYFeLRaqZgt3H9z78LevIn4w0MtSgMbjUh+N13349MhSQniZakpbIRJsIkotfQEq9kCboJwmtyBce4VwxACKLqvAycx+5EUz2JjlBtn5mgLsltpHLiF9Z5G55XFUoIUy5q6OrKKdvk44SRgEKzGJ0u/+5AaqAxAPtoEt9hTfr4x47jhEquY5aOesb8XFLcdS5af5PsNnL5CkWs9mvysyh42pkIHxwPKwOsGO8+Q8utb36o5oaskanUJXim4EQuM2uux5IqKRtfkhE0gzjZq/EW3rvSxD2AKkGGQsoer577nGybFTpF4xzhSioYCzKOQdijHR9KJR/dx3+08pOf/ZSFlie4P6x4MKRf6Brjo4+9AdTYpYiBFh2R9b2RohNh/Uj+lDfBhg0P1oVBaI517L/vxIJT7UNkB/UVad5W690Mv9yMBrZFAdXsYTUbJqYbbWrMuSAZOYdYvrL0MILImsHDdbmnxadW3TG3RtK1SmdvBth8kUSFVSpN8SB2Dv+MyAsgOs5c=,
		// appid=wxdfda9493a8ddb75b, mch_id=1510628061, return_code=SUCCESS}
		String string = map.get("req_info");
		if (StringUtils.isNotBlank(string)) {
			String decryptData = AES256Utils.decryptData(string);
			InputStream iss = new ByteArrayInputStream(decryptData.getBytes());
			InputStreamReader isReader2 = new InputStreamReader(iss, "utf-8");
			Map<String, String> doXMLParse = XmlPullUtil.parse2(isReader2);

			String refund_status = doXMLParse.get("refund_status");
			// 判断是否退款成功
			if (StringUtils.isNotBlank(refund_status) && refund_status.equals("SUCCESS")) {// 成功
				try {
					manageCaseBoxService.successBackPay(doXMLParse);
					return "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml> ";
				} catch (Exception e) {
					return "<xml><return_code><![CDATA[FAIL]]></return_code>";
				}

			} else if (StringUtils.isNotBlank(refund_status) && !refund_status.equals("SUCCESS")) {
				try {
					manageCaseBoxService.failBackPay(doXMLParse);
					return "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml> ";
				} catch (Exception e) {
					return "<xml><return_code><![CDATA[FAIL]]></return_code>";
				}
			}
		}
		return "<xml><return_code><![CDATA[FAIL]]></return_code>";
	}

	/**
	 * @author 刘成
	 * @since 2018年8月10日
	 * @param request
	 * @param response
	 *            通知地址 回调服务器 支付结果(这个回调 如果不返回给微信服务器 是否成功回调标示 则会一直回调8次 一直到返回成功标示位置)
	 *
	 */
	@RequestMapping("/payCallback")
	@ResponseBody
	public String payCallback(HttpServletRequest request, HttpServletResponse response) {
		String inputLine = "";
		String notityXml = "";
		try {
			while ((inputLine = request.getReader().readLine()) != null) {
				notityXml += inputLine;
			}
			// 关闭流
			request.getReader().close();

			// 解析成Map
			InputStream iss = new ByteArrayInputStream(notityXml.getBytes());
			InputStreamReader isReader2 = new InputStreamReader(iss, "utf-8");
			Map<String, String> map = XmlPullUtil.parse(isReader2);

			// 判断 支付是否成功
			if ("SUCCESS".equals(map.get("result_code"))) {
				// 获得 返回的商户订单号
				try {
					manageCaseBoxService.payBack(map);
					return "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";
				} catch (Exception e) {

					return "<xml><return_code><![CDATA[FAIL]]></return_code></xml>";
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "<xml><return_code><![CDATA[FAIL]]></return_code></xml>";
	}

	/**
	 * 描述: 发送远程请求 获得代码示例 参数： @param urls 访问路径 参数： @param param 访问参数-字符串拼接格式,
	 * 例：port_d=10002&port_g=10007&country_a= 返回类型: String
	 */
	private String getRemotePortData(String urls, String param) {
		try {
			URL url = new URL(urls);
			HttpURLConnection conn = (HttpURLConnection) url.openConnection();
			// 设置连接超时时间
			conn.setConnectTimeout(30000);
			// 设置读取超时时间
			conn.setReadTimeout(30000);
			conn.setRequestMethod("POST");
			if (StringUtils.isNotBlank(param)) {
				conn.setRequestProperty("Origin", "https://sirius.searates.com");// 主要参数
				// conn.setRequestProperty("Referer",
				// "https://sirius.searates.com/cn/port?A=ChIJP1j2OhRahjURNsllbOuKc3Y&D=567&G=16959&shipment=1&container=20st&weight=1&product=0&request=&weightcargo=1&");
				conn.setRequestProperty("X-Requested-With", "XMLHttpRequest");// 主要参数
			}
			// 需要输出
			conn.setDoInput(true);
			// 需要输入
			conn.setDoOutput(true);
			// 设置是否使用缓存
			conn.setUseCaches(false);
			// 设置请求属性
			conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
			conn.setRequestProperty("Connection", "Keep-Alive");// 维持长连接
			conn.setRequestProperty("Charset", "UTF-8");

			if (StringUtils.isNotBlank(param)) {
				// 建立输入流，向指向的URL传入参数
				DataOutputStream dos = new DataOutputStream(conn.getOutputStream());
				dos.writeBytes(param);
				dos.flush();
				dos.close();
			}
			// 输出返回结果
			InputStream input = conn.getInputStream();
			int resLen = 0;
			byte[] res = new byte[1024];
			StringBuilder sb = new StringBuilder();
			while ((resLen = input.read(res)) != -1) {
				sb.append(new String(res, 0, resLen));
			}
			return sb.toString();
		} catch (MalformedURLException e) {
		} catch (IOException e) {
		}
		return "";
	}

	/**
	 * @author liuCheng
	 * @since 2018年11月13日 下午5:05:30
	 * @param openId
	 * @return
	 * @throws Exception
	 *             微信测试人员退款接口
	 */
	// @RequestMapping("/backPayToTest")
	// @ResponseBody
	public Map<String, String> backPayToTest(String openId, String transaction_id, String total_fee) throws Exception {
		Map<String, String> map = new HashMap<>();
		String nonce_str = DictionaryUtils.getRandomStr();
		String out_refund_no = "tk" + new Date().getTime() + nonce_str.substring(0, 2);
		Map<String, String> restultMap = new HashMap<>();

		String MCHID = WxConfig.MCH_ID;
		String KEY = WxConfig.KEY;
		String appid = WxConfig.APPID;

		map.put("appid", appid);
		map.put("mch_id", MCHID);
		map.put("nonce_str", nonce_str);
		map.put("transaction_id", transaction_id);
		map.put("out_refund_no", out_refund_no);
		map.put("total_fee", total_fee);
		map.put("refund_fee", total_fee);
		map.put("refund_account", "REFUND_SOURCE_RECHARGE_FUNDS");
		map.put("notify_url", WxConfig.DOMAIN_URL + "/xcx/sds");
		String stringA = DictionaryUtils.formatUrlMap(map, false, false);
		String stringSignTemp = stringA + "&key=" + KEY;
		String sign = Md5Util.wxXcxHash(stringSignTemp).toUpperCase();

		StringBuffer paramBuffer = new StringBuffer();
		paramBuffer.append("<xml>");
		paramBuffer.append("<appid>" + appid + "</appid>");
		paramBuffer.append("<mch_id>" + MCHID + "</mch_id>");
		paramBuffer.append("<nonce_str>" + nonce_str + "</nonce_str>");
		paramBuffer.append("<sign>" + sign + "</sign>");
		paramBuffer.append("<transaction_id>" + transaction_id + "</transaction_id>");
		paramBuffer.append("<out_refund_no>" + out_refund_no + "</out_refund_no>");
		paramBuffer.append("<total_fee>" + total_fee + "</total_fee>");
		paramBuffer.append("<refund_fee>" + total_fee + "</refund_fee>");
		paramBuffer.append("<refund_account>" + "REFUND_SOURCE_RECHARGE_FUNDS" + "</refund_account>");
		paramBuffer.append("<notify_url>" + WxConfig.DOMAIN_URL + "/xcx/sds" + "</notify_url>");
		paramBuffer.append("</xml>");
		String postData = ClientCustomSSL.postData(WxConfig.BACKPAY_URL,
				new String(paramBuffer.toString().getBytes(), "ISO8859-1"));

		InputStream is = new ByteArrayInputStream(postData.getBytes());
		InputStreamReader isReader = new InputStreamReader(is, "utf-8");
		Map<String, String> map1 = XmlPullUtil.parse(isReader);

		String result_code = map1.get("result_code");
		if (StringUtils.isNotBlank(result_code) && result_code.equals("SUCCESS")) {// 退款申请成功
			restultMap.put("message", "退款申请已发送成功");
		} else {
			restultMap.put("jumpPage", "0");
			restultMap.put("message", "未知错误，请稍后重试");
		}

		return restultMap;
	}

	/**
	 * 帮助中心
	 *
	 * @return
	 */
	@RequestMapping("/helpCenter")
	@ResponseBody
	public List<HelpCenter> helpCenter() {
		HelpCenterExample example = new HelpCenterExample();
		example.createCriteria().andSignEqualTo(1);
		List<HelpCenter> helpCenters = helpCenterMapper.selectByExample(example);
		return helpCenters;
	}

	/**
	 * 问题反馈
	 *
	 * @return
	 */
	@RequestMapping("/question")
	@ResponseBody
	public AjaxResult question(HelpCenter helpCenter) {
		helpCenter.setSign(2);
		helpCenter.setTime(new Date());
		int insert = helpCenterMapper.insert(helpCenter);
		if (insert == 1) {
			return new AjaxResult();
		}
		return new AjaxResult("请重试");
	}
}
